//
//  FinishInviteVC.m
//  HengYouCai
//
//  Created by ycgwl on 2017/5/21.
//  Copyright © 2017年 lwj. All rights reserved.
//

#import "FinishInviteVC.h"
@interface FinishInviteVC ()
//title
@property (weak, nonatomic) IBOutlet UILabel *statusLabel;
//投资金额
@property (weak, nonatomic) IBOutlet UILabel *inviteMoneyLabel;
//投资期限
@property (weak, nonatomic) IBOutlet UILabel *inviteTimeLabel;
//预估收益
@property (weak, nonatomic) IBOutlet UILabel *yuGuShouYiLabel;
//投资奖励
@property (weak, nonatomic) IBOutlet UILabel *jiangLiLable;
//状态提示
@property (weak, nonatomic) IBOutlet UILabel *statusTipsLabel;

@property (weak, nonatomic) IBOutlet UILabel *tipsLabel;


@property (weak, nonatomic) IBOutlet UILabel *inviteMoney;
@property (weak, nonatomic) IBOutlet UILabel *inviteTime;
@property (weak, nonatomic) IBOutlet UILabel *yuGuShouYi;
@property (weak, nonatomic) IBOutlet UIView *jiangLiView;
@property (weak, nonatomic) IBOutlet NSLayoutConstraint *jiangliHeight;
@property (weak, nonatomic) IBOutlet UILabel *jiangliLab;
// 阴影view
@property (weak, nonatomic) IBOutlet UIView *shadowView;
@end

@implementation FinishInviteVC

- (void)viewDidLoad {
    [super viewDidLoad];
    
    self.statusLabel.text = self.paymentSuccessTitle;
    self.statusTipsLabel.text = self.paymentSuccessTips;
    self.inviteMoneyLabel.text = self.paymentSuccessAmountLabel;
    self.inviteTimeLabel.text = self.paymentSuccessPlstimeLimitLabel;
    self.yuGuShouYiLabel.text = self.paymentSuccessProfitLabel;
   
    self.tipsLabel.text = self.paymentSuccessrRwardTips;

    _shadowView.layer.shadowColor = UIColor.blackColor.CGColor;
    _shadowView.layer.shadowOpacity = 0.3;
    _shadowView.layer.shadowOffset = CGSizeMake(0, 0);
    _shadowView.layer.cornerRadius = 10;
    self.view.backgroundColor = [UIColor whiteColor];
    CGFloat statusH = [[UIApplication sharedApplication] statusBarFrame].size.height;

    UIView *footerView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, f_Device_w, f_Device_h - 575 -44-statusH)];
    footerView.backgroundColor = Normal_BackColor;
    
    self.tableView.tableFooterView = footerView;
    _inviteMoney.text = [NSString stringWithFormat:@"%@元",_totalArr[@"inviteMoney"]];
    _inviteTime.text = _totalArr[@"inviteTime"];
    _yuGuShouYi.text = _totalArr[@"yuGuShouYi"];

    if (_modelArr.count<1) {
        _jiangliHeight.constant = 0.1;
        _jiangliLab.text = @"";
        [self.view viewWithTag:10].hidden = YES;
        
    }else{
         self.jiangliLab.text = self.paymentSuccessRewardLabel;
//        _jiangliLab.text =    //@"投资奖励";
        
        _jiangliHeight.constant = 45;
        _jiangLiLable.attributedText = [self handlerTouZiZengSong:_modelArr];
    }
    
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    return 1;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"cellID"];
    if (!cell) {
        cell  = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleValue1 reuseIdentifier:@"cellID"];

        cell.backgroundColor = Normal_BackColor;
        cell.selectionStyle = UITableViewCellSelectionStyleNone;
    }
    return cell;
}

- (IBAction)finish:(id)sender {
    [self dismissViewControllerAnimated:YES completion:nil];
}
- (void)setTotalArr:(NSDictionary *)totalArr
{
    
    _totalArr = totalArr;
}


/** 处理投资赠送字符串 */
- (NSAttributedString *)handlerTouZiZengSong:(NSArray<TouziZengSongModel*> *)modelArr{
    NSMutableAttributedString * totalStr = [[NSMutableAttributedString alloc] initWithString:@""];
    if (!modelArr.count) {//不存在直接返回
        return totalStr;
    }
    for (TouziZengSongModel* model in modelArr) {
        NSString * bonusesStr = @"0";
        NSString * cdkeyTypeStr = @"";
        if (model.type.integerValue == 0) {//红包
            bonusesStr = [NSString stringWithFormat:@"%.0f",model.bonuses.floatValue];
            cdkeyTypeStr = @"元";
        }else if (model.type.integerValue == 1){//加息券
            bonusesStr = [NSString stringWithFormat:@"%.2f%%",model.bonuses.floatValue*100];
        }else if (model.type.integerValue == 2){//卡
            bonusesStr = [NSString stringWithFormat:@"%.0f",model.bonuses.floatValue];
            //处理后缀
            if (model.cdkeyType.integerValue == -1) {
                cdkeyTypeStr = @"元";
            }else if (model.cdkeyType.integerValue == 0){
                cdkeyTypeStr = @"天";
            }else if (model.cdkeyType.integerValue == 1){
                cdkeyTypeStr = @"月";
            }else if (model.cdkeyType.integerValue == 2){
                cdkeyTypeStr = @"年";
            }
        }
        //数值变色
        [totalStr appendAttributedString:[[NSAttributedString alloc] initWithString:[NSString stringWithFormat:@"%@%@",bonusesStr,cdkeyTypeStr] attributes:@{NSFontAttributeName:[UIFont systemFontOfSize:12],NSForegroundColorAttributeName:Normal_RedColor}]];
        //处理名字
        [totalStr appendAttributedString:[[NSAttributedString alloc] initWithString:[NSString stringWithFormat:@"%@，",model.title] attributes:@{NSFontAttributeName:[UIFont systemFontOfSize:12],NSForegroundColorAttributeName:Normal_333Color}]];
    }
    //删除最后一个，号
    [totalStr deleteCharactersInRange:(NSRange){totalStr.length-1,1}];
    return totalStr;
}

@end
